package 面试.OOM;/*
 *@Author: helen
 *@Date:   2021/4/16 16:33
 *@Description:
 */

import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;

//-Xmx10m -Xmx10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
public class DirectBufferMemoryDemo {
    public static void main(String[] args) {
        System.out.println("配置的maxDirectMemory:"+(sun.misc.VM.maxDirectMemory()/(double)1024/ 1024) + "MB");
        try {
            TimeUnit.MILLISECONDS.sleep(3000);} catch (InterruptedException e) {e.printStackTrace(); }
        ByteBuffer bb = ByteBuffer.allocateDirect(6*1024*1024);//配置5MB,使用6MB
    }//Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
}


